class TaskQueue {
  constructor() {
      this.list = [];
      this.isRunning = false;
  }
  addTask(task) {
      this.list.push(task);
      if(this.isRunning) {
          return;
      }
      this.start();
  }
  shift() {
      return this.list.length > 0 ? this.list.shift() : null;
  }
  run() {
      let task = this.shift();
      if(!task) {
          this.isRunning = false;
          return;
      }
      task();
  }
  start() {
      this.isRunning = true;
      this.run();
  }
}
module.exports = TaskQueue;
